{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# !pip install datasets pandas numpy huggingface_hub\n",
    "#!pip install python-dotenv\n",
    "# !pip install openai==1.6.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from huggingface_hub import notebook_login\n",
    "from datasets import load_dataset\n",
    "notebook_login()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "combined_dataeset = load_dataset(\"CognitiveLab/translation-combined-dataset\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "kannada_dataset = load_dataset(\"oscar-corpus/OSCAR-2201\",\"kn\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import random"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "!pip install python-dotenv"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from openai import OpenAI\n",
    "\n",
    "client = OpenAI(\n",
    "    # This is the default and can be omitted\n",
    "    api_key = \"\",\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "text = \"i love going to the moon\"\n",
    "\n",
    "\n",
    "json_response_format = {\n",
    "    \"src\" : \"\",\n",
    "    \"tgt\" : \"\"\n",
    "}\n",
    "romanised_kannada_response = client.chat.completions.create(\n",
    "        model=\"gpt-3.5-turbo-1106\",\n",
    "        temperature=0.3,\n",
    "        response_format={\"type\": \"json_object\"},\n",
    "        messages=[\n",
    "            {\n",
    "                \"role\": \"system\",\n",
    "                \"content\": f\"\"\"You are an expert at translating any given language into romanised kannda which is kannada which is written in english\n",
    "                you always return the translation in the following where src is the source language and tgt is the romanised kannda translation you \n",
    "                provide in the following json format\n",
    "                ```translation:{json_response_format}```\"\"\"\n",
    "            },\n",
    "            {\n",
    "            \"role\": \"user\",\n",
    "            \"content\": f\"\"\"given the following text \n",
    "            \\n\n",
    "            {text} \n",
    "            \\n\n",
    "            translate it into romanised kannada which is kannada which is written in english\n",
    "            here are a few examples for you to understand the format\n",
    "            \n",
    "            if the text is in english covert into kannada then convert it into romanised kannada which is kannada which is written in english\n",
    "            \n",
    "            example 1\n",
    "            src: What is your name?\n",
    "            tgt: ninna hesaru yenu?\n",
    "            \n",
    "            example 3\n",
    "            src: ಆ ಕಾಲ ಹೋಗೇ ಬಿಡ್ತಾ\n",
    "            tgt: aa kaala hogey bidtaa\n",
    "            \n",
    "            example 4\n",
    "            src: ನಿಮ್ಮ ಹೆಸರು ಯಾವುದು?\n",
    "            tgt: nimma hesaru yaavudu?\n",
    "            \n",
    "            always retun the translation in the following json format\n",
    "            ```translation:{json_response_format}```\n",
    "            \"\"\"\n",
    "                \n",
    "            }\n",
    "        ]\n",
    "    )\n",
    "print(eval(romanised_kannada_response.choices[0].message.content))\n",
    "\n",
    "# try:\n",
    "#     romanised_response = eval(romanised_kannada_response.choices[0].message.content)\n",
    "#     print(romanised_response)\n",
    "\n",
    "#     # Check if the format is correct and meets the criteria\n",
    "#     if (\n",
    "#         isinstance(romanised_response, dict)\n",
    "#         and \"translation\" in romanised_response\n",
    "#         and isinstance(romanised_response[\"translation\"], dict)\n",
    "\n",
    "        \n",
    "#     ):\n",
    "#         print(romanised_response)\n",
    "#         print(\"Short response format is correct.\")\n",
    "#         # print(\"Short response format is correct.\")\n",
    "#     else:\n",
    "#         print(\"Short response format is incorrect. Running the query again.\")\n",
    "# except:\n",
    "#     print(\"Short response format is incorrect. Running the query again.\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
